package vis.manage.demo;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vis.core.common.security.AuthOnlyLogin;
import vis.core.common.security.AuthPublic;
import vis.core.domain.sys.SRS;

@RestController
@RequestMapping("/auth/demo")
public class DemoAuthController {
    /**
     * AuthPublic 开放接口，跳过权限认证
     */
    @AuthPublic
    @RequestMapping("/login")
    public Object login(String a) {
        StpUtil.login(10001);
        return SRS.bySuccess("AuthPublic 开放接口，跳过权限认证---10001 登录成功");
    }

    @RequestMapping("/logout")
    public Object logout(String a) {
        StpUtil.logout(10001);
        return SRS.bySuccess("10001 退出登录");

    }

    @AuthPublic
    @RequestMapping("/isLogin")
    public Object isLogin(String a) {
        boolean login = StpUtil.isLogin();
        return SRS.bySuccess("当前登录状态===>" + login);

    }

    @AuthOnlyLogin
    @RequestMapping("/onlyCheckLogin")
    public Object auth1(String a) {
        return SRS.bySuccess("AuthOnlyLogin 只检查登录权限，不检查资源权限");
    }

    //    检查是否具备角色 d1
    @SaCheckRole("d1")
    @RequestMapping("/dd/d11")
    public Object d11(String a) {
        return SRS.bySuccess("检查是否具备角色 d1");
    }

    //    检查是否具备权限  dd:d2
    @SaCheckPermission("dd:d2")
    @RequestMapping("/dd/d12")
    public Object d12(String a) {
        return SRS.bySuccess("检查是否具备权限  dd:d2");
    }

}
